﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Ext.Net;

public partial class SYS_POPEDOM_MyMenu_Manage : BasePage
{
    public static string json;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    //绑定当前用户我的菜单记录
    private void BindData()
    {
        DataTable tmpDB = CommonLib.BLL.SYS_SHORTCUT.GetList(" USER_ID='" + BS_LoginUserID + "'", "MENU_NO").Tables[0];
        this.Store1.DataSource = tmpDB;
        this.Store1.DataBind();
    }

    //删除我的菜单
    protected void extBtn_Delete_Click(object sender, DirectEventArgs e)
    {
        int nCount = 0;
        RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
        nCount = sm.SelectedRows.Count;
        if (nCount == 0)
        {
            X.Msg.Alert("系统提示", "请先选择要删除的记录！").Show();
            return;
        }

        json = e.ExtraParams["Values"];

        X.Msg.Confirm("系统提示", "是否删除选中行?", new MessageBoxButtonsConfig
        {
            Yes = new MessageBoxButtonConfig
            {
                Handler = "Ext.net.DirectMethods.DoDelMyMenu();",
                Text = "是"
            },
            No = new MessageBoxButtonConfig
            {
                Text = "否"
            }
        }).Show();
    }
  

    //完成实际删除

    [DirectMethod]
    public void DoDelMyMenu()
    {
        RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
        try
        {
            foreach (SelectedRow row in sm.SelectedRows)
            {
                foreach (DataRow dr in CommonLib.BLL.SYS_SHORTCUT.GetList(" MENU_NO = " + row.RecordID).Tables[0].Select())
                {
                 
                        CommonLib.BLL.SYS_SHORTCUT.Delete(BS_LoginUserID, row.RecordID);
                  
                }
            }
        }
        catch
        {
            X.Msg.Alert("系统提示", "删除记录失败！").Show();
            return;
        }
        this.GridPanel1.Reload();
    
    }



    //获得增加页面url
    [DirectMethod]
    public string GetAddMyMenuWinUrl()
    {
        string Url = G_Url_allstring + "/SYS_POPEDOM/MyMenu_Edit.aspx";
        return Url;
    }

    protected void Store1_RefreshData(object sender, StoreRefreshDataEventArgs e)
    {
        BindData();
    }
}
